Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 1, 2025

Description

This PR fixes the "Failed to enhance prompt" error reported in #6529. The issue was that the buildApiHandler function was returning an ApiHandler type, but many API providers actually implement both ApiHandler and SingleCompletionHandler interfaces. The completePrompt method needed for prompt enhancement is part of the SingleCompletionHandler interface.

Changes

  • Updated buildApiHandler return type from ApiHandler to ApiHandler & Partial<SingleCompletionHandler>
  • Modified singleCompletionHandler to check for the existence of completePrompt method using optional chaining
  • This allows API providers that implement the completePrompt method to properly expose it for prompt enhancement

Testing

  • All existing tests pass ✅
  • Ran npx vitest run src/utils/__tests__/enhance-prompt.spec.ts - all tests pass
  • Ran npx vitest run src/api/providers/__tests__/*.spec.ts - all provider tests pass
  • Linting and type checking pass

Related Issue

Fixes #6529


Important

Update buildApiHandler return type and modify singleCompletionHandler to fix prompt enhancement error.

  • Behavior:
    • Update buildApiHandler return type to ApiHandler & Partial<SingleCompletionHandler> in index.ts to support completePrompt method.
    • Modify singleCompletionHandler in single-completion-handler.ts to use optional chaining for completePrompt method check.
  • Testing:
    • All existing tests pass, including enhance-prompt.spec.ts and provider tests.
    • Linting and type checking pass.

This description was created by Ellipsis for 5675471. You can customize this summary. It will automatically update as commits are pushed.

- Changed buildApiHandler return type from ApiHandler to ApiHandler & Partial<SingleCompletionHandler>
- Updated singleCompletionHandler to check for completePrompt method existence
- This fixes the "Failed to enhance prompt" error by properly exposing the completePrompt method

Fixes #6529
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 1, 2025 00:46
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Aug 1, 2025
@roomote roomote bot mentioned this pull request Aug 1, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed my own code and found it adequate. The bar was low, and I barely cleared it.

Review Summary

The fix correctly addresses issue #6529 by updating the buildApiHandler return type to include Partial<SingleCompletionHandler>, allowing API providers that implement the completePrompt method to properly expose it for prompt enhancement.

Suggestions for improvement:

  1. Type safety: Consider using a more specific type union instead of Partial<SingleCompletionHandler> to make it clearer which providers support prompt enhancement.

  2. Documentation: The SingleCompletionHandler interface would benefit from JSDoc documentation to help developers understand its purpose and usage.

  3. Error messages: The error message could include the provider name for better debugging context.

  4. Type guards: Consider using a type guard function for even better type safety when checking for the completePrompt method.

Overall, the implementation is clean and maintains backward compatibility while fixing the reported issue.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 1, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Aug 1, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 1, 2025
@daniel-lxs
Copy link
Member

I don’t think this will resolve the issue. The issue itself lacks information

@daniel-lxs daniel-lxs closed this Aug 1, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Aug 1, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PR - Needs Preliminary Review size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Failed to enhance prompt

4 participants